Poincaré and SimBio

Mauro Silberberg

PhD Student in Physics

Universidad de Buenos Aires, Argentina

Currently doing an internship at EBI-EBML, UK

Tutorial’s GitHub repo

https://bit.ly/simbio-combine2023

In a nutshell

Poincaré

A Python library to

define and simulate

dynamical systems.

SimBio

Built on top of poincaré, adding functionality to:

  • easily simulate mass-action reactions,
  • import from SBML,
  • and more to come…

Yet another Python tool?

AMICI, Brian 2, CBMPy, COBRApy, COPASI, E-Cell 4, GillesPy2, GINsim, KaSim, Lattice Microbes, LibSBMLSim, MaBoSS, MASSpy, NetPyNe, NEURON, OpenCOR, pyNeuroML, PySB, PySceS, RBApy, Simmune, SimVascular, Smoldyn, tellurium, XP, …

And these are the ones listed in BioSimulators.org!

What’s new?

Using modern Python

  • type annotations
  • dataclass_transform

Integrated with IDEs:

  • autocomplete
  • refactoring

Being in Python

What do we mean by this?

Being in Python

Wrappers to libraries in other languages (C, C++)

  • controlled from Python
  • can export to Python
    • pandas.DataFrame
    • matplotlib

But not extendable from Python.

PyData ecosystem just used after the simulation is done.

Being in Python

Example:

Random Parameter Scans in COPASI

  • Choose from: uniform, normal, poisson or gamma
  • Cannot:
    • use one from scipy.stats?
    • add a new integration method?

The main selling point of Python is it huge ecosystem.

Writing models

Interexchange standards:

  • SBML
  • CellML

to (re)use with different tools.

Approaches to create them:

  • GUI (graphical user interface)
    • COPASI
  • DSL (domain specific language)
    • Antimony
  • Python (or whatever language)

DSL: Antimony

Simple reaction with first-order mass-action kinetics:

model example1
  S1 -> S2; k1*S1
  S1 = 10
  S2 = 0
  k1 = 0.1
end

And in Python:

import tellurium as te

r = te.loada('''
model example1
  S1 -> S2; k1*S1
  S1 = 10
  S2 = 0
  k1 = 0.1
end
''')

can be reused as is in other languages

strings!

IDE don’t like strings

With strings, IDE cannot provide:

  • Syntax highlighting
  • Code completion
  • Code search
  • Refactoring
  • Static analysis

Programming without them is like

…parking without power steering?

Antimony extension for VSCode

By Steve Ma et. al from the University of Washington

Language Server Protocol (LSP)

\(\rightarrow\) now easier to add support for a language.

But a maintenance burden for small community?

Must adapt to changes in: Antimony, LSP, VSCode

Writing models in Python

Using standard Python to reuse tooling from the community:

  • linter \(\rightarrow\) ruff ⚡️

  • formatter \(\rightarrow\) black (PSF project)

  • type-checker \(\rightarrow\) mypy, pyright (Microsoft)

  • LSP \(\rightarrow\) multiple editors

Widely used tools \(\rightarrow\) highly tested and will be maintained

Now, to showcase them…

SimBio vs Antimony

Simple reaction with first-order mass-action kinetics:

model example1
  S1 -> S2; k1*S1
  S1 = 10
  S2 = 0
  k1 = 0.1
end
class Example1(Compartment):
    S1: Species = initial(default=10)
    S2: Species = initial(default=0)
    k1: Parameter = assign(default=0.1)
    r = Reaction(
        reactants=[S1],
        products=[S2],
        rate_law=k1 * S1,
    )
class Example1(Compartment):
    S1: Species = initial(default=10)
    S2: Species = initial(default=0)
    k1: Parameter = assign(default=0.1)
    r = MassAction(
        reactants=[S1],
        products=[S2],
        rate=k1,
    )

Roadmap

  • Add SED-ML import/export

  • Add SBML export

  • Add volume to Compartment (needed for units in simbio).

  • New integrators (stochastic integrators)

  • New simulations (parameter sweeps)

  • Events

Conclusion

Created two modular Python packages:

  • poincare, to define and simulate dynamical systems
  • simbio, add-ons specific to Systems Biology

Modularity

can be used* by a broader community

*debugged, improved, maintained

Being in Python

use tooling* and libraries from the (huge) Python community

*linter, formatters, static analyzers, editor integration, etc.